#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @time     : 2019/7/4 17:03
# @Author   : BYF
# file      : request.py
# @version  :

import requests
import json
from config.config import time_out

class Request:

    def __init__(self):
        self.time=time_out

    def request(self,method,url,headers,data):

        if method == 'POST':
            if headers==None:
                res = requests.post(url=url,params=data)
            else:
                res = requests.post(url=url, headers=headers,params=data)


        elif method == 'GET':
            if headers==None:
                res = requests.get(url=url,params =data)
            else:
                res = requests.get(url=url, headers=headers, params =data)

        else:
            res = None

        if res.status_code == 200:
            response = json.loads(res.content)
            time_consuming = res.elapsed.total_seconds  # 接口响应总时间时间
        else:
            try:
                json.loads(res.content)
            except:
                response=res
            else:
                response = json.loads(res.content)


        response={
            'status_code':res.status_code,
            'response':response
        }

        return response

if __name__=='__main__':
    file_name = '登录接口测试用例.xlsx'
    sheet_num = 0

    method='GET'
    url='https://api-test.lefull.cn/apartment-new/api/v1/apartment/findApartmentList?filterApartmentAuthority=1'
    headers={'keys':'lisa_969f5efd4406ac9b2e676fbc87063d4a'}
    data=None

    res=Request().request(method,url,headers,data)
    print(res)
